package org.etlt.extract;

import org.etlt.SettingCheck;

public class DatabaseExtractSetting extends ExtractorSetting{

    private boolean autoResolve = true;
    private String pkName;
    private boolean union = false;
    private String pkDql;
    private String dql;
    private String dqlByPk;
    private String datasource;

    public boolean isAutoResolve() {
        return autoResolve;
    }
    public void setAutoResolve(boolean autoResolve) {
        this.autoResolve = autoResolve;
    }
    public String getPkName() {
        return pkName;
    }

    public void setPkName(String pkName) {
        this.pkName = pkName;
    }

    public boolean isUnion() {
        return union;
    }

    public void setUnion(boolean union) {
        this.union = union;
    }

    public String getPkDql() {
        return pkDql;
    }

    public void setPkDql(String pkDql) {
        this.pkDql = pkDql;
    }

    public String getDql() {
        return dql;
    }

    public void setDql(String dql) {
        this.dql = dql;
    }

    public String getDqlByPk() {
        return dqlByPk;
    }

    public void setDqlByPk(String dqlByPk) {
        this.dqlByPk = dqlByPk;
    }

    public String getDatasource() {
        return datasource;
    }

    public void setDatasource(String dataSource) {
        this.datasource = dataSource;
    }


    @Override
    public void check(){
        super.check();
        if(!autoResolve){
            if(getColumns().size() == 0){
                throw new IllegalArgumentException("missing column definition.");
            }
        }
        getColumnSettings().forEach(setting -> {
            if(setting instanceof SettingCheck){
                ((SettingCheck)setting).check();
            }
        });
        assertNotNull("datasource", datasource);
    }
}
